package yunmouren.top.place.Commands;

import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import yunmouren.top.place.JourneyMapApi;

import java.util.Objects;

public class RegisterNavigationPoint extends CommandBase {
    @Override
    public String getName() {
        return "place";
    }

    @Override
    public String getUsage(ICommandSender sender) {
        return "/place";
    }

    @Override
    public int getRequiredPermissionLevel() {
        return 1;
    }

    @Override
    public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
        try {
            if (args.length==0) {
                sender.sendMessage(new TextComponentString(String.valueOf(sender.getEntityWorld().getWorldType().getId())));
            } else if (args.length == 5) {
                String name = args[0];
                int DIM = Integer.parseInt(args[1]);
                int X = Integer.parseInt(args[2]);
                int Y = Integer.parseInt(args[3]);
                int Z = Integer.parseInt(args[4]);
                JourneyMapApi.show(name, DIM, new BlockPos(X, Y, Z));
            } else if (args.length == 4) {
                String name = args[0];
                int X = Integer.parseInt(args[1]);
                int Y = Integer.parseInt(args[2]);
                int Z = Integer.parseInt(args[3]);
                JourneyMapApi.show(name, getPlayer(server, sender).getEntityWorld().getWorldType().getId(), new BlockPos(X, Y, Z));
            } else {
                sender.sendMessage(new TextComponentString("/place to Get World ID"));
                sender.sendMessage(new TextComponentString("/place <name> <X Y Z> To Create Place"));
                sender.sendMessage(new TextComponentString("/place <name> <DIM> <X Y Z> To Create Place"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static EntityPlayerMP getPlayer(MinecraftServer server, ICommandSender sender) {
        return server.getPlayerList().getPlayerByUsername(sender.getName());
    }
}
